script_enemy_main{

let starttime=120;

let speakingside=0;
let movecharacter=0;
let characterscroll=0;
let oldside=0;

let i=0;
let j=0;
let letter=0;
let letters=[];
let letterscale=[];
let letterfade=[];
let letterred=[];
let lettergreen=[];
let letterblue=[];

let line="";
let writingtime=0;
let nextline=0;
let newword=0;
let wordsize=0;
let lineypos=0;

let wait=0;
let busywriting=0;
let shortbreak=0;
let skipped=0;
let currentline=1;
let linenumber=1;
let textcolor=[0,0,0];
let newcolor=[textcolor[0],textcolor[1],textcolor[2],0,0,0];
let nameappear=0;

let lastline=19;
let waittime=180;
let enableZ=true;
let enableskip=true;

let GRtextbar=("\script\Images\OtherEffects\Textbar.png");
let GRtext=("\script\Images\OtherEffects\TextDialogue.png");
let GRnames=("\script\Images\OtherEffects\Names.png");

let SEtext=("\script\SoundEffects\text1.wav");

#include_function "script/Functions/PortraitsVariables.txt";

let OBJtextbar=0; let OBJtext=0; let OBJleft=0; let OBJright=0;
let textbarscale=0;

let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let frame=0; let time=0;

@Initialize{
	SetLife(1000);
	SetX(cx);
	SetY(-1000);
	
	LoadPortrait("Masahiro",1);
	LoadPortrait("Tomomi",1);
	LoadPortrait("Takeo",1);

	#include_function "script/Functions/PortraitsLoad.txt";
	
	SetCommonData("InEvent",1);
	SetCommonData("BackgroundStop",1);
	
	SetCommonData("Boss1Move",2);
	SetCommonData("Boss2Move",2);
}
	
@MainLoop{

CollectItems;

if(time==starttime){
	OBJtextbar=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJtextbar,6); Obj_SetPosition(OBJtextbar,cx,maxy-70); ObjEffect_SetTexture(OBJtextbar,GRtextbar);
	ObjEffect_SetRenderState(OBJtextbar,ALPHA); ObjEffect_SetScale(OBJtextbar,1,1);
	ObjEffect_SetScale(OBJtextbar,1,0);
	ObjEffect_SetPrimitiveType(OBJtextbar,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJtextbar,4);
	ObjEffect_SetVertexXY(OBJtextbar,0,-190,-50); ObjEffect_SetVertexUV(OBJtextbar,0,0,0);
	ObjEffect_SetVertexXY(OBJtextbar,1,190,-50); ObjEffect_SetVertexUV(OBJtextbar,1,380,0);
	ObjEffect_SetVertexXY(OBJtextbar,2,-190,50); ObjEffect_SetVertexUV(OBJtextbar,2,0,100);
	ObjEffect_SetVertexXY(OBJtextbar,3,190,50); ObjEffect_SetVertexUV(OBJtextbar,3,380,100);
	ObjEffect_SetVertexColor(OBJtextbar,0,200,255,255,255); ObjEffect_SetVertexColor(OBJtextbar,1,200,255,255,255);
	ObjEffect_SetVertexColor(OBJtextbar,2,200,255,255,255); ObjEffect_SetVertexColor(OBJtextbar,3,200,255,255,255);

	OBJleft=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJleft,5); Obj_SetPosition(OBJleft,cx-100,cy+60); ObjEffect_SetTexture(OBJleft,CHEmpty);
	ObjEffect_SetPrimitiveType(OBJleft,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJleft,4); ObjEffect_SetAngle(OBJleft,0,180,0);
	ObjEffect_SetVertexXY(OBJleft,0,-175,-175); ObjEffect_SetVertexUV(OBJleft,0,0,0);
	ObjEffect_SetVertexXY(OBJleft,1,175,-175); ObjEffect_SetVertexUV(OBJleft,1,350,0);
	ObjEffect_SetVertexXY(OBJleft,2,-175,175); ObjEffect_SetVertexUV(OBJleft,2,0,350);
	ObjEffect_SetVertexXY(OBJleft,3,175,175); ObjEffect_SetVertexUV(OBJleft,3,350,350);
	ObjEffect_SetVertexColor(OBJleft,0,255,255,255,255); ObjEffect_SetVertexColor(OBJleft,1,255,255,255,255);
	ObjEffect_SetVertexColor(OBJleft,2,255,255,255,255); ObjEffect_SetVertexColor(OBJleft,3,255,255,255,255);

	OBJright=(Obj_Create(OBJ_EFFECT));
	ObjEffect_SetLayer(OBJright,5); Obj_SetPosition(OBJright,cx+100,cy+60); ObjEffect_SetTexture(OBJright,CHEmpty);
	ObjEffect_SetPrimitiveType(OBJright,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(OBJright,4); ObjEffect_SetAngle(OBJright,0,0,0);
	ObjEffect_SetVertexXY(OBJright,0,-175,-175); ObjEffect_SetVertexUV(OBJright,0,0,0);
	ObjEffect_SetVertexXY(OBJright,1,175,-175); ObjEffect_SetVertexUV(OBJright,1,350,0);
	ObjEffect_SetVertexXY(OBJright,2,-175,175); ObjEffect_SetVertexUV(OBJright,2,0,350);
	ObjEffect_SetVertexXY(OBJright,3,175,175); ObjEffect_SetVertexUV(OBJright,3,350,350);
	ObjEffect_SetVertexColor(OBJright,0,255,255,255,255); ObjEffect_SetVertexColor(OBJright,1,255,255,255,255);
	ObjEffect_SetVertexColor(OBJright,2,255,255,255,255); ObjEffect_SetVertexColor(OBJright,3,255,255,255,255);
}
if(time>=starttime){

if(textbarscale<1 && linenumber<lastline){ textbarscale+=0.1; }
if(textbarscale>0 && linenumber==lastline){ textbarscale-=0.1; }
if(textbarscale<0){ Obj_Delete(OBJtextbar); }
ObjEffect_SetScale(OBJtextbar,1,textbarscale);

if(nextline==1){ i=0; j=0; nextline=0; wordsize=0; lineypos=0; wait=0; currentline++; linenumber++; }
if(nextline==2){ i=0; j=0; nextline=0; wordsize=0; lineypos=0; wait=0; currentline=lastline; linenumber=lastline; }


WriteLine(1,"Tomomi","Aaaaaand%.%.%.% Stop!",CHTomomiNormal01);
WriteLine(2,"Masahiro","Oh,% hi Tomomi and Takeo.",CHMasahiroNormal06);
WriteLine(3,"Tomomi","You`re a bit too close to the finish,% Masahiro!+We can`t let you defeat us in this game!",CHTomomiNormal02);
WriteLine(4,"Takeo","Better be careful,% Masahiro.+Tomomi is determined to win.",CHTakeoNormal01);
WriteLine(5,"Tomomi","Yeah!+We already passed most of the rest, so you`re probably our last obstacle.",CHTomomiNormal01);
WriteLine(6,"Masahiro","Then,% did you run into Tomoko on the way here?",CHMasahiroNormal02);
WriteLine(7,"Tomomi","Come to think of,% you were grouped with Tomoko,% weren`t you?",CHTomomiNormal03);
WriteLine(8,"Takeo","Does that mean you lost her?",CHTakeoNormal02);
WriteLine(9,"Masahiro","One moment she was with me,% and the other she was gone.",CHMasahiroNormal01);
WriteLine(10,"Masahiro","I don`t think she just got lost like that though.+Maybe she ran away?",CHMasahiroNormal01);
WriteLine(11,"Tomomi","Did you do something wrong to her?",CHTomomiNormal03);
WriteLine(12,"Masahiro","Not that I know of,% although she did seem a bit upset at the festival.",CHMasahiroNormal19);
WriteLine(13,"Tomomi","Maybe she`s angry that you`re the one doing all the danmaku fights!",CHTomomiNormal04);
WriteLine(14,"Takeo","Only you would get upset about games,% Tomomi.",CHTakeoNormal03);
WriteLine(15,"Tomomi","But it`s serious business!+Just like this,% if we beat Masahiro in this match,% we win two things at once!",CHTomomiNormal05);
WriteLine(16,"Masahiro","I don`t really feel like another danmaku fight%.%.%.",CHMasahiroNormal07);
WriteLine(17,"Takeo","Please,% just go along with the flow.+You know Tomomi is hard to stop when she`s talking about her favorite things.",CHTakeoNormal04);
WriteLine(18,"Masahiro","Sigh.% Well,% maybe I can concentrate better during the battle and figure out where Tomoko could have gone.",CHMasahiroNormal22);

if(linenumber==1 && i==1){ nameappear=7; }
if(linenumber==4 && i==1){ nameappear=13; }

#include_function "script/Functions/TextWriter.txt";

} //>starttime

if(linenumber==lastline && wait==1){ SetCommonData("PlayMusic",2); }
if(skipped==2 && wait==1){ SetCommonData("PlayMusic",2); }


if(linenumber==lastline && wait==60){
	SetShotColor(255,255,255);

	Obj_Delete(OBJleft);
	Obj_Delete(OBJright);
	Obj_Delete(OBJtextbar);

	SetCommonData("InEvent",0);
//	SetCommonData("BackgroundStop",0);

//	VanishEnemy; SetCommonData("Conversation",2); // end conversation
	SetLife(0); // start battle
}


time++;
frame++;
}

}